var a = getApp(),
    util = require("../../utils/util.js"),
    WXBizDataCrypt = require('../../utils/RdWXBizDataCrypt.js');

Page({
    data: {
        top: "-420"
    },
    wdyjk: function() {
        wx.navigateTo({
            url: "../deposit/index"
        });
    },
    wdsc: function() {
        wx.navigateTo({
            url: "mysc"
        });
    },
    wddz: function() {
        wx.navigateTo({
            url: "../wddz/xzdz"
        });
    },
    wdsp: function() {
        wx.navigateTo({
            url: "../waterticket/index"
        });
    },
    wdqg: function() {
        wx.navigateTo({
            url: "../xsqg/order"
        });
    },
    wdpt: function() {
        wx.navigateTo({
            url: "../collage/order"
        });
    },
    wdyhq: function() {
        wx.navigateTo({
            url: "myyhq"
        });
    },
    yjfk: function() {
        wx.navigateTo({
            url: "myyjfk"
        });
    },
    about: function() {
        wx.navigateTo({
            url: "about"
        });
    },
    zxkf: function () {
        wx.navigateTo({
            url: "zxkf"
        });
    },
    go_detaulted: function () {
        wx.navigateTo({
            url: "../distribution/detaulted"
        });
    },
    seller: function() {
        if (this.data.StoreName && this.data.StorePassword) {
            this.sign();
        } else {
            wx.navigateTo({
                url: "../sjzx/login"
            });
        }
    },
    fx: function() {
        wx.navigateTo({
            url: "../distribution/core"
        });
    },
    daili: function() {
        wx.navigateTo({
            url: "../daili/index"
        });
    },
    MyDistribution: function () {
        var e = this,
            t = wx.getStorageSync("users").id;
        a.util.request({
            url: "entry/wxapp/MyDistribution",
            cachetime: "0",
            data: {
                user_id: t,
                user_name: wx.getStorageSync("nike_name"),
                user_tel: e.data.PhoneNumber,
            },
            success: function (t) {
                wx.navigateTo({
                    url: "../distribution/core"
                });
            }
        });
    },
    getPhoneNumberFunc: function (e) {
        let ths = this;
        if ("getPhoneNumber:ok" == e.detail.errMsg) {
            var pc = new WXBizDataCrypt(getApp().getOpenId, getApp().getSK);
            var res = pc.decryptData(e.detail.encryptedData, e.detail.iv)
            this.setData({
                PhoneNumber: res.phoneNumber
            });
            wx.setStorageSync("PhoneNumber", res.phoneNumber);
            ths.MyDistribution();
        }
    },
    bindGetUserInfo: function(t) {
        "getUserInfo:ok" == t.detail.errMsg && (this.setData({
            hydl: !1
        }), this.changeData());
    },
    changeData: function() {
        var n = this;
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.userInfo"] ? wx.getUserInfo({
                    success: function(t) {
                        a.util.request({
                            url: "entry/wxapp/login",
                            cachetime: "0",
                            data: {
                                openid: getApp().getOpenId,
                                img: t.userInfo.avatarUrl,
                                name: t.userInfo.nickName
                            },
                            header: {
                                "content-type": "application/json"
                            },
                            dataType: "json",
                            success: function(t) {

                            }
                        });
                        var e = t.userInfo;
                        n.setData({
                            avatarUrl: e.avatarUrl,
                            nickName: e.nickName
                        });
                    }
                }) : (n.setData({
                    hydl: !0
                }));
            }
        });
    },
    jumps: function(t) {
        var e = t.currentTarget.dataset.id,
            a = t.currentTarget.dataset.name,
            n = t.currentTarget.dataset.appid,
            o = t.currentTarget.dataset.src,
            i = t.currentTarget.dataset.wb_src,
            r = t.currentTarget.dataset.type;
        1 == r ? (wx.navigateTo({
            url: o
        })) : 2 == r ? (wx.setStorageSync("vr", i), wx.navigateTo({
            url: "../car/car"
        })) : 3 == r && wx.navigateToMiniProgram({
            appId: n
        });
    },
    onLoad: function(t) {
        a.setNavigationBarColor(this), a.pageOnLoad(this), this.changeData();
        var o = this,
            e = wx.getStorageSync("users").id;
        a.util.request({
            url: "entry/wxapp/MyCoupons",
            cachetime: "0",
            data: {
                user_id: e
            },
            success: function(t) {
                o.setData({
                    yhnum: t.data.length
                });
            }
        }), a.util.request({
            url: "entry/wxapp/system",
            cachetime: "0",
            success: function(t) {
                o.setData({
                    system: t.data
                });
            }
        }), a.util.request({
            url: "entry/wxapp/CheckRetail",
            cachetime: "0",
            success: function(t) {
                o.setData({
                    fxset: t.data
                });
            }
        }), a.util.request({
            url: "entry/wxapp/ad",
            cachetime: "0",
            success: function(t) {
                for (var e = [], a = 0; a < t.data.length; a++) "7" == t.data[a].type && e.push(t.data[a]);
                o.setData({
                    lblist: e
                });
            }
        }), a.util.request({
            url: "entry/wxapp/Llz",
            cachetime: "0",
            data: {
                type: "3,4"
            },
            success: function(t) {
                for (var e = [], a = [], n = 0; n < t.data.length; n++) 3 == t.data[n].type && e.push(t.data[n]),
                    4 == t.data[n].type && a.push(t.data[n]);
                o.setData({
                    dbllz: e,
                    zbllz: a
                });
            }
        }), wx.getSystemInfo({
            success: function(t) {
                "android" != t.platform && o.setData({
                    top: "-330"
                });
            }
        });
    },
    feedback: function(t) {
        wx.navigateTo({
            url: "feedback"
        });
    },
    wallet: function(t) {
        wx.navigateTo({
            url: "../wallet/wallet"
        });
    },
    set_up: function(t) {
        wx.navigateTo({
            url: "set_up"
        });
    },
    receive: function(t) {
        wx.navigateTo({
            url: "receive"
        });
    },
    integral: function(t) {
        wx.navigateTo({
            url: "../integral/myintegral"
        });
    },
    sign_in: function(t) {
        wx.navigateTo({
            url: "rankings"
        });
    },
    sjrz: function(t) {
        var e = wx.getStorageSync("users").id;
        a.util.request({
            url: "entry/wxapp/CheckRz",
            cachetime: "0",
            data: {
                user_id: e
            },
            success: function(t) {
                0 != t.data ? 1 == t.data.state ? wx.showModal({
                    title: "",
                    content: "系统正在审核中"
                }) : 2 == t.data.state ? wx.showModal({
                    title: "",
                    content: "您已经入驻过了"
                }) : 3 == t.data.state ? wx.showModal({
                    title: "",
                    content: "您的入驻申请已被拒绝，点击确定进行编辑",
                    success: function(t) {
                        t.confirm && wx.navigateTo({
                            url: "../ruzhu/index?state=3"
                        });
                    }
                }) : wx.showModal({
                    title: "",
                    content: "您的入驻已经到期,请联系平台管理员续费"
                }) : wx.navigateTo({
                    url: "../ruzhu/index"
                });
            }
        });
    },
    sign: function(t) {
        wx.showLoading({
            title: "正在进入商家",
            mask: !0
        });
        a.util.request({
            url: "entry/wxapp/StoreLogin",
            cachetime: "0",
            data: {
                user: wx.getStorageSync("StoreName"),
                password: wx.getStorageSync("StorePassword"),
            },
            success: function(t) {
                if (null != t.data.storeid) {
                    wx.setStorageSync("sjdsjid", t.data.storeid);
                    wx.navigateTo({
                        url: "../sjzx/sjzx/sjzx"
                    })
                } else {
                    wx.showModal({
                        title: "提示",
                        content: t.data,
                        success: function(res) {
                            wx.navigateTo({
                                url: "../sjzx/login"
                            })
                        }
                    });
                }
            }
        });
    },
    onShow: function() {
        var e = this,
            t = wx.getStorageSync("users").id,
            n = util.formatTime(new Date()).substring(0, 10).replace(/\//g, "-");
        this.setData({
            StoreName: wx.getStorageSync("StoreName"),
            StorePassword: wx.getStorageSync("StorePassword"),
            PhoneNumber: wx.getStorageSync("PhoneNumber")
        })
        a.util.request({
            url: "entry/wxapp/UserInfo",
            cachetime: "0",
            data: {
                user_id: t
            },
            success: function(t) {
                ("" != t.data.dq_time || t.data.dq_time >= n.toString()) && (t.data.ishy = 1),
                e.setData({
                    userInfo: t.data
                });
            }
        });
    },
});